﻿@using Microsoft.AspNetCore.Authentication.AzureADB2C.UI
@using Microsoft.Extensions.Options
@inject IOptionsMonitor<AzureADB2COptions> AzureADB2COptions

<AuthorizeView>
    <Authorized>
        @if (canEditProfile)
        {
            <a href="AzureADB2C/Account/EditProfile">Hello, @context.User.Identity.Name!</a>
        }
        else
        {
            <text>Hello, @context.User.Identity.Name!</text>
        }
        <a href="AzureADB2C/Account/SignOut">Log out</a>
    </Authorized>
    <NotAuthorized>
        <a href="AzureADB2C/Account/SignIn">Log in</a>
    </NotAuthorized>
</AuthorizeView>

@code {
    private bool canEditProfile;

    protected override void OnInitialized()
    {
        var options = AzureADB2COptions.Get(AzureADB2CDefaults.AuthenticationScheme);
        canEditProfile = !string.IsNullOrEmpty(options.EditProfilePolicyId);
    }
}
